
package bbchess.dialogs;

import bbchess.units.ChessBoard;
import bbchess.units.ChessPiece;
import bbchess.units.pieces.Pawn;
import bbchess.util.ImageLoader;
import java.awt.Image;
import javax.swing.ImageIcon;

/**
 * PawnPromotionDialog: This dialog displays pawn promotion options.
 * @author Tyler Eastman
 */
public class PawnPromotionDialog extends ChessDialog {

    Pawn piece;
    Image wQueen = null;
    Image wKnight = null;
    Image wBishop = null;
    Image wRook = null;
    Image bQueen = null;
    Image bKnight = null;
    Image bBishop = null;
    Image bRook = null;

    ChessBoard board;

    /** Creates new form ChatDialog */
    public PawnPromotionDialog(java.awt.Frame parent, ChessPiece piece) {
        super(parent, true, false);
        this.setTitle("Chat");
        this.piece = (Pawn) piece;
        initComponents();
        board = super.getMainGui().getChessBoard();
        int unitSize = board.getSquareSize();

        wQueen = ImageLoader.getwQueenImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);
        wKnight = ImageLoader.getwKnightImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);
        wBishop = ImageLoader.getwBishopImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);
        wRook = ImageLoader.getwRookImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);
        bQueen = ImageLoader.getbQueenImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);
        bKnight = ImageLoader.getbKnightImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);
        bBishop = ImageLoader.getbBishopImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);
        bRook = ImageLoader.getbRookImage().getScaledInstance(unitSize, unitSize, Image.SCALE_DEFAULT);

        if (piece.getColor().equals("white")) {
            queenButton.setIcon(new ImageIcon(wQueen));
            knightButton.setIcon(new ImageIcon(wKnight));
            bishopButton.setIcon(new ImageIcon(wBishop));
            rookButton.setIcon(new ImageIcon(wRook));
        }

        else {
            queenButton.setIcon(new ImageIcon(bQueen));
            knightButton.setIcon(new ImageIcon(bKnight));
            bishopButton.setIcon(new ImageIcon(bBishop));
            rookButton.setIcon(new ImageIcon(bRook));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        knightButton = new javax.swing.JButton();
        bishopButton = new javax.swing.JButton();
        rookButton = new javax.swing.JButton();
        queenButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Pawn Promotion");
        setAlwaysOnTop(true);
        setIconImage(null);
        setResizable(false);

        knightButton.setPreferredSize(new java.awt.Dimension(53, 53));
        knightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                knightButtonActionPerformed(evt);
            }
        });

        bishopButton.setPreferredSize(new java.awt.Dimension(53, 53));
        bishopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bishopButtonActionPerformed(evt);
            }
        });

        rookButton.setPreferredSize(new java.awt.Dimension(53, 53));
        rookButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rookButtonActionPerformed(evt);
            }
        });

        queenButton.setPreferredSize(new java.awt.Dimension(53, 53));
        queenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                queenButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(knightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bishopButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rookButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(queenButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(knightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(bishopButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(rookButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(queenButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void knightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knightButtonActionPerformed
        piece.promoteTo("N");
        dispose();
    }//GEN-LAST:event_knightButtonActionPerformed

    private void bishopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bishopButtonActionPerformed
        piece.promoteTo("B");
        dispose();
    }//GEN-LAST:event_bishopButtonActionPerformed

    private void rookButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rookButtonActionPerformed
        piece.promoteTo("R");
        dispose();
    }//GEN-LAST:event_rookButtonActionPerformed

    private void queenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queenButtonActionPerformed
        piece.promoteTo("Q");
        dispose();
    }//GEN-LAST:event_queenButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bishopButton;
    private javax.swing.JButton knightButton;
    private javax.swing.JButton queenButton;
    private javax.swing.JButton rookButton;
    // End of variables declaration//GEN-END:variables

}
